package hot_100;

import java.util.Arrays;

public class 零钱兑换 {
    public static void main(String[] args) {
        int s = coinChange(new int[]{
                1, 2, 5
        }, 11);
        System.out.println(s);
    }

    public static int coinChange(int[] coins, int amount) {
        int[] dp = new int[amount + 1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        for (int num : coins) {
            for (int i = num; i <= amount; i++) {
                if(dp[i - num]!=Integer.MAX_VALUE)
                dp[i] = Math.min(dp[i], dp[i - num] + 1);
            }
        }
        return dp[amount] == Integer.MAX_VALUE ? -1 : dp[amount];
    }
}
